﻿using System.Web.Mvc;
using NHibernate.Burrow.Util;
using Ornament.MVCWebFrame.Models;
using Ornament.IO;
using System;
using System.IO;
using System.Web;
using System.Linq;
namespace Ornament.MVCWebFrame.Areas.Settings.Controllers
{
    public class ApplicationController : Controller
    {
        //
        // GET: /System/Application/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Folder(string rootPath)
        {
            if (rootPath == null)
            {
                rootPath = "~/Content/images";
            }
            ViewData["Parent"] = rootPath.Replace("~/", Request.ApplicationPath);
            DirectoryInfo parent = new DirectoryInfo(Request.MapPath(rootPath));
            return View(parent);
        }
        [System.Web.Mvc.HttpPost()]
        public ActionResult Files(string directory, string filter)
        {
            string path = Request.MapPath("~/" + HttpUtility.UrlDecode(directory));
            DirectoryInfo parent = new DirectoryInfo(path);
            var files = from a in parent.GetFilesEx(filter) select a.FullName.Replace(Request.PhysicalApplicationPath, Request.ApplicationPath).Replace("\\", "/");
            return Json(files);
        }
    }
}